<?php
namespace Admin\Controller;

use Think\Controller;
use Think\Model;
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/6/8 0008
 * Time: 13:45
 */
class IndexController extends Controller
{
    public function index()
    {
        $this->display();
    }

    public function main()
    {
        $this->display();
    }

    public function top()
    {
        $this->display();
    }

    public function menu()
    {
        $this->display();
    }

    public function test()
    {
      $config=  array('DB_TYPE' => 'mysql',     // mysql,mysqli,pdo
//    'DB_DSN' => 'mysql:host=localhost;dbname=php39;charset=utf8',
            'DB_USER' => 'root',      // 用户名
            'DB_PWD' => '123456',          // 密码
            'DB_PORT' => '3306',        // 端口
            'DB_PREFIX' => 'p39_',    // 数据库表前缀
            'DB_HOST' => 'localhost', // 服务器地址
            'DB_NAME' => 'php39',          // 数据库名
            'DB_CHARSET' => 'utf8'    // 数据库编码默认采用utf8
        );
//        echo "123</br>";
//        $hostModel = M('goods',C(DB_PREFIX),$config);
        $hostModel = M('goods');
        var_dump($hostModel->where("id=12")->find());

        //实例化空模型
//        $Model = new Model();
//或者使用M快捷方法是等效的
//        $Model = M();
//        $data = $Model->query('SELECT * FROM p39_goods ');
////        var_dump($data);
//       $DATA= md5("sfh1229D2F5C5B9A166209857DA7BFAD5CA");
//        echo $DATA;
    }

    public function json()
    {
        //数组转json
       $res= json_encode(array(
            'rescode'=>"0",
            'resmessage'=>'成功'
        ));
        echo $res;
        //json转数组
        var_dump(json_decode($res));
    }

    public function string()
    {
        $str1 = "&&  123456  &&";
        $str1=trim(trim($str1, "&&"));
        $length = strlen($str1);
        echo $length;
    }
}